package com.qf.question01.vo;

import java.util.HashMap;

/**
 * 该vo类用于定义通用的 返回json的字段
 */
public class ResultVo extends HashMap {

    /**
     * 该方法用于返回通用成功的json
     * code = 1
     * msg = "ok"
     * @return
     */
    public static ResultVo ok(){
        final ResultVo resultVo = new ResultVo();
        resultVo.put("code",1);
        resultVo.put("msg","ok");
        return resultVo;
    }


    /**
     * 该方法用于封装通用错误的json
     * code = -1
     * msg = “error”
     * @return
     */
    public static ResultVo error(){
        final ResultVo resultVo = new ResultVo();
        resultVo.put("code",-1);
        resultVo.put("msg","error");
        return resultVo;
    }


    /**
     * 该方法用于封装通用错误的json，接收自定义的错误消息
     * code = -1
     * msg = “error”
     * @return
     */
    public static ResultVo error(String msg){
        final ResultVo resultVo = new ResultVo();
        resultVo.put("code",-1);
        resultVo.put("msg",msg);
        return resultVo;
    }


    /**
     * 该方法用于封装通用错误的json，接收自定义的错误消息
     * code
     * msg
     * @return
     */
    public static ResultVo error(Integer code ,String msg){
        final ResultVo resultVo = new ResultVo();
        resultVo.put("code",code);
        resultVo.put("msg",msg);
        return resultVo;
    }


}
